package Testing;
import java.util.Scanner;
import java.util.*;
public class Testing{
	 public static void main(String[] args) {
		 	Scanner in = new Scanner(System.in);
	        Course gdsx=new Course("001","高等数学","教101","周一8：00——9：40");
	        Course xxds=new Course("002","线性代数","教102","周二8：00——9：40");
	        Course java=new Course("003","Java","教201","周三1：30——3：10");
	        Course cyy=new Course("004","C语言","教202","周四1：30——3：10");
	        Course dxwl=new Course("005","大学物理","教203","周五8：00——9：40");
	        Course tiyu=new Course("006","体育","体育馆","周五10：00——11：40");

	        Course[] zong=new Course[] {gdsx,xxds,java,cyy,dxwl,tiyu};//总课程列表
	        
	        Teacher wang=new Teacher("0001","王老师","男", new Course[]{gdsx,xxds});
	        Teacher zhang=new Teacher("0002","张老师","男",new Course[]{java,cyy});
	        Teacher li=new Teacher("0003","李老师","女",new Course[]{dxwl});
	        Teacher shi=new Teacher("004","石老师","男",new Course[]{tiyu});

	        Teacher[] t=new Teacher[] {wang,zhang,li,shi};//总老师列表
	        
	        gdsx.setTeacher(wang);
	        xxds.setTeacher(wang);
	        java.setTeacher(zhang);
	        cyy.setTeacher(zhang);
	        dxwl.setTeacher(li);
	        tiyu.setTeacher(shi);

	        
	        Student liu=new Student("202001","刘同学","男",new Course[]{gdsx,xxds,cyy,java,dxwl});
	        Student chen=new Student("202002","陈同学","女",new Course[]{xxds,java,cyy,dxwl,tiyu,gdsx});


	        
			System.out.println("欢迎使用选课系统");
			int a = 1;
	while(a==1)	{	

		System.out.println("1.学生选课");
		System.out.println("2.教师开设课程");
		System.out.println("3.打印课表信息");
			int c  = in.nextInt();
			if (c == 1){
				System.out.println("输入学生编号");
				System.out.println("1.刘同学，2.陈同学");
				int x=in.nextInt();
				
				if(x==1) {//刘同学
					System.out.println("已选课程");
					for(int i = 0; i<liu.course.length; i++){
				        System.out.println("课程编号:"+liu.course[i].number+"\t课程名称:"+liu.course[i].name+"\t上课时间:"
				                +liu.course[i].time+"\t上课地点:"+liu.course[i].place+"\t教师:"+liu.course[i].teacher.name);
				    }
					System.out.println("所有课程");
					for(int i = 0; i<zong.length; i++){
				        System.out.println("课程编号:"+zong[i].number+"\t课程名称:"+zong[i].name+"\t上课时间:"
				                +zong[i].time+"\t上课地点:"+zong[i].place+"\t教师:"+zong[i].teacher.name);
				    }
					System.out.println("1.选课，2.退课");
					int x1=in.nextInt();
					if(x1==1) {														//刘同学选课
						System.out.println("请输入课程编号");
						int x4=in.nextInt();

							liu.xuanke(zong[x4-1]);
	
						System.out.println("现有课程");
						for(int i = 0; i<liu.course.length; i++){
					        System.out.println("课程编号:"+liu.course[i].number+"\t课程名称:"+liu.course[i].name+"\t上课时间:"
					                +liu.course[i].time+"\t上课地点:"+liu.course[i].place+"\t教师:"+liu.course[i].teacher.name);
						}
					}
				
					else if (x1==2) {  												//刘同学退课
						System.out.println("请输入课程编号");
						int x4=in.nextInt();
							liu.tuike(zong[x4-1]);
							System.out.println("已选课程");
							for(int i = 0; i<chen.course.length; i++){
						        System.out.println("课程编号:"+chen.course[i].number+"\t课程名称:"+chen.course[i].name+"\t上课时间:"
						                +chen.course[i].time+"\t上课地点:"+chen.course[i].place+"\t教师:"+chen.course[i].teacher.name);
						    }

						}
					}
				
				
				else if(x==2) {                                         			//陈同学
					System.out.println("已选课程");
					for(int i = 0; i<chen.course.length; i++){
				        System.out.println("课程编号:"+chen.course[i].number+"\t课程名称:"+chen.course[i].name+"\t上课时间:"
				                +chen.course[i].time+"\t上课地点:"+chen.course[i].place+"\t教师:"+chen.course[i].teacher.name);
				    }
					System.out.println("所有课程");
					for(int i = 0; i<zong.length; i++){
				        System.out.println("课程编号:"+zong[i].number+"\t课程名称:"+zong[i].name+"\t上课时间:"
				                +zong[i].time+"\t上课地点:"+zong[i].place+"\t教师:"+zong[i].teacher.name);
				    }
					System.out.println("1.选课，2.退课");
					int x1=in.nextInt();
					if(x1==1) {                                         			//陈同学选课
						System.out.println("请输入课程编号");
						int x4=in.nextInt();
						
							chen.xuanke(zong[x4-1]);
						
		
						
						System.out.println("现有课程");
						for(int i = 0; i<chen.course.length; i++){
					        System.out.println("课程编号:"+chen.course[i].number+"\t课程名称:"+chen.course[i].name+"\t上课时间:"
					                +chen.course[i].time+"\t上课地点:"+chen.course[i].place+"\t教师:"+chen.course[i].teacher.name);
						}
					}
					
					else if (x1==2) {                                         			//陈同学退课
						System.out.println("请输入课程编号");
						int x5=in.nextInt();
					
							chen.tuike(zong[x5-1]);
							System.out.println("现有课程");
							for(int i = 0; i<chen.course.length; i++){
						        System.out.println("课程编号:"+chen.course[i].number+"\t课程名称:"+chen.course[i].name+"\t上课时间:"
						                +chen.course[i].time+"\t上课地点:"+chen.course[i].place+"\t教师:"+chen.course[i].teacher.name);
							}
						}
				}
			}
			else if(c==2) {																//增加课程
				System.out.println("选择任课老师");
				System.out.println("1.王老师 2.张老师 3.李老师 4.石老师");
				int ls=in.nextInt();
				System.out.println("请输入课程编号");	
				String bh=in.next();
				System.out.println("请输入课程名称");	
				String xk=in.next();
				System.out.println("请输入上课地点");	
				String dd=in.next();
				System.out.println("请输入上课时间");	
				String sj=in.next();
				Course z=new Course(bh,xk,dd,sj);
				z.setTeacher(t[ls-1]);
					
				 Course[] zong1 = new Course[zong.length+1];						//定义变量储存数据
			    	for (int i=0;i<zong.length;i++) {
			    		zong1[i]=zong[i];
			    		
				}
			    	zong1[zong.length]=z;
			    	
			    	zong =new Course[zong.length+1];								//进行替换
			    	for (int i=0;i<zong.length;i++) {
			    		zong[i]=zong1[i];
			    		
			    	}
			    	
			
			}
			else if (c==3) {														//学生信息输出
			    System.out.println("学生编号:"+liu.number+
			            "\n学生姓名:"+liu.name+
			            "\n学生性别:"+liu.sex);

			    for(int i = 0; i<liu.course.length; i++){
			        System.out.println("课程编号:"+liu.course[i].number+"\t课程名称:"+liu.course[i].name+"\t上课时间:"
			                +liu.course[i].time+"\t上课地点:"+liu.course[i].place+"\t教师:"+liu.course[i].teacher.name);
			    }

			    System.out.println("\n"+"学生编号:"+chen.number+
			            "\n学生姓名:"+chen.name+
			            "\n学生性别:"+chen.sex);

			    for(int i = 0; i<chen.course.length; i++){
			        System.out.println("课程编号:"+chen.course[i].number+"\t课程名称:"+chen.course[i].name+"\t上课时间:"
			                +chen.course[i].time+"\t上课地点:"+chen.course[i].place+"\t教师:"+chen.course[i].teacher.name);
				        }
			   
			}
			else {
				System.out.println("输入错误，重新选择");
				
			}
			
	}
			
			
			

	    }
	}
